package org.brownflat.watergate.resources.mysql;

import org.brownflat.watergate.resources.MySqlUpgrade;
import org.springframework.stereotype.Component;

/**
 * <p>&copy Rupert Jones 2011,2012</p>
 *
 * @author rup
 */
@Component
public class Upgrade0019ContributorStatus implements MySqlUpgrade {

    private static final int VERSION = 19;

    @Override
    public int getSequence() {
        return VERSION;
    }

    @Override
    public String getSql() {
        return "CREATE TABLE `wgate_review_contribution` (\n"
                + " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + " `contributor` varchar(255) NOT NULL,\n"
                + " `review` int(11) NOT NULL,\n"
                + " `contr_state` int(11) NOT NULL,\n"
                + " `created_at` timestamp NOT NULL,\n"
                + " `updated_at` timestamp NOT NULL,\n"
                + "  UNIQUE KEY `rev_UNIQUE` (`review`, `contributor`),\n"
                + " PRIMARY KEY (`id`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\n" +
                " CREATE TABLE `wgate_review_contribution_state` ("
                + " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
                + " `name` varchar(100) NOT NULL,\n"
                + " `next_state` int(11),\n"
                + " `previous_state` int(11),\n"
                + " `created_at` timestamp NOT NULL,\n"
                + " `updated_at` timestamp NOT NULL,\n"
                + "  UNIQUE KEY `name_UNIQUE` (`name`),\n"
                + "  PRIMARY KEY (`id`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\n" +
                " DROP TABLE wgate_review_contributor;\n" +
                " INSERT INTO wgate_review_contribution_state (id, name, next_state, previous_state, created_at, updated_at) VALUES (1, 'NEW', 2, null, current_timestamp, current_timestamp);\n" +
                " INSERT INTO wgate_review_contribution_state (id, name, next_state, previous_state, created_at, updated_at) VALUES (2, 'IN PROGRESS', 3, 1, current_timestamp, current_timestamp);\n" +
                " INSERT INTO wgate_review_contribution_state (id, name, next_state, previous_state, created_at, updated_at) VALUES (3, 'COMPLETED', 4, 2, current_timestamp, current_timestamp);\n" +
                " INSERT INTO wgate_review_contribution_state (id, name, next_state, previous_state, created_at, updated_at) VALUES (4, 'CLOSED', null, 3, current_timestamp, current_timestamp);\n";
    }

    @Override
    public String getName() {
        return "Create auto review trigger";
    }
}
